package cn.tedu.sp06;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@EnableCircuitBreaker
@SpringBootApplication
public class Sp06RibbonApplication {
    /*
    * 创建RestTemplate实例
    * 放入spring容器
    */
    @Bean
    @LoadBalanced       //对RestTemplate 进行增强  添加负载均衡功能
    public RestTemplate restTemplate(){
        //设置调用超时时间 超时后认为调用失败
        SimpleClientHttpRequestFactory f=new SimpleClientHttpRequestFactory();
        f.setConnectTimeout(1000);  //建立连接等待时间
        f.setReadTimeout(1000);     //连接建立后 发送请求后 等待接收响应的时间

        return  new RestTemplate(f);
    }

    public static void main(String[] args) {
        SpringApplication.run(Sp06RibbonApplication.class, args);
    }

}
